module XMonad.Util.Hmenu (hmenu) where

-- | Usage
--
-- import XMonad.Util.Hmenu
--
-- ...
--
-- myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
-- [ ((modMask, xK_p), hmenu myTheme)
-- , ... ]
--
-- For additional information on myTheme please refer to XMonad.Util.Themes.

import Control.Monad.Trans (MonadIO)
import XMonad.Layout.Decoration (Theme(..))
import XMonad.Core (spawn)

hmenu :: MonadIO m => Theme -> m ()
hmenu th = spawn $ "e=`hmenu_run " ++ args opts ++ "` && eval \"exec $e\""
  where opts = [ ("fn", fontName th)
               , ("nf", inactiveTextColor th)
               , ("sf", activeTextColor th)
               , ("nb", inactiveColor th)
               , ("sb", activeColor th) ]

args :: [(String, String)] -> String
args = unwords . map args'
  where args' (k, v) = "-" ++ k ++ " '" ++ v ++ "'"

